package com.ruoyi.web.controller.wisdom;

import java.util.List;

import com.ruoyi.common.config.HeadNum;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.framework.util.GetSessionValueUtil;
import com.ruoyi.framework.util.ShiroUtils;
import com.ruoyi.wisdom.domain.FzServiceVisitor;
import com.ruoyi.wisdom.service.IFzServiceVisitorService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

import javax.servlet.http.HttpSession;

/**
 * 访客登记Controller
 * 
 * @author ruoyi
 * @date 2020-03-05
 */
@Controller
@RequestMapping("/wisdom/visitor")
public class FzServiceVisitorController extends BaseController
{
    private String prefix = "wisdom/visitor";

    @Autowired
    private IFzServiceVisitorService fzServiceVisitorService;

    @RequiresPermissions("wisdom:visitor:view")
    @GetMapping()
    public String visitor()
    {
        return prefix + "/visitor";
    }

    /**
     * 查询访客登记列表
     */
    @RequiresPermissions("wisdom:visitor:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(HttpSession session, FzServiceVisitor fzServiceVisitor)
    {
        startPage();
        fzServiceVisitor.setcId(GetSessionValueUtil.getCommunity());
        List<FzServiceVisitor> list = fzServiceVisitorService.selectFzServiceVisitorList(fzServiceVisitor);
        return getDataTable(list);
    }

    /**
     * 导出访客登记列表
     */
    @RequiresPermissions("wisdom:visitor:export")
    @Log(title = "访客登记", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(FzServiceVisitor fzServiceVisitor)
    {
        List<FzServiceVisitor> list = fzServiceVisitorService.selectFzServiceVisitorList(fzServiceVisitor);
        ExcelUtil<FzServiceVisitor> util = new ExcelUtil<FzServiceVisitor>(FzServiceVisitor.class);
        return util.exportExcel(list, "visitor");
    }

    /**
     * 新增访客登记
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存访客登记
     */
    @RequiresPermissions("wisdom:visitor:add")
    @Log(title = "访客登记", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(FzServiceVisitor fzServiceVisitor)
    {
        fzServiceVisitor.setVisitorId(HeadNum.VISITOR_HEAD+ DateUtils.getTimeMillis());
        fzServiceVisitor.setcId(GetSessionValueUtil.getCommunity());
        fzServiceVisitor.setCreateName(ShiroUtils.getSysUser().getUserName());
        return toAjax(fzServiceVisitorService.insertFzServiceVisitor(fzServiceVisitor));
    }

    /**
     * 修改访客登记
     */
    @GetMapping("/edit/{visitorId}")
    public String edit(@PathVariable("visitorId") String visitorId, ModelMap mmap)
    {
        FzServiceVisitor fzServiceVisitor = fzServiceVisitorService.selectFzServiceVisitorById(visitorId);
        mmap.put("fzServiceVisitor", fzServiceVisitor);
        return prefix + "/edit";
    }

    /**
     * 修改保存访客登记
     */
    @RequiresPermissions("wisdom:visitor:edit")
    @Log(title = "访客登记", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(FzServiceVisitor fzServiceVisitor)
    {
        fzServiceVisitor.setUpdateName(ShiroUtils.getSysUser().getUserName());
        return toAjax(fzServiceVisitorService.updateFzServiceVisitor(fzServiceVisitor));
    }

    /**
     * 删除访客登记
     */
    @RequiresPermissions("wisdom:visitor:remove")
    @Log(title = "访客登记", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(fzServiceVisitorService.deleteFzServiceVisitorByIds(ids));
    }
}
